import http, {HttpOptions} from "../http"

// 响应接口
export interface GetUserRoleRes {
    code: number;
    msg: string;
    data: {
        total: number;
        size: number;
        current: number;
        records: {
            userId: number;
            userNick: string;
            roleId: Record<string, unknown>[];
            roleName: Record<string, unknown>[];
            status: number;
            time: string;
        }[];
    };
    timestamp: number;
    now: string;
}

/**
 * 获取用户角色
 * @param {string} current
 * @param {string} size
 * @returns
 */
export function getUserRole(current: number, size: number): Promise<GetUserRoleRes> {
    const config:HttpOptions  = {
        msg: false,
        token: true,
        load: false,
    }
    return http.get(`/userRole?current=${current}&size=${size}`,config);
}

// 参数接口
export interface PutUserRoleParams {
    userId?: number;
    roleId?: string;
}

// 响应接口
export interface PutUserRoleRes {
    code: number;
    msg: string;
    data: string;
    timestamp: number;
    now: string;
}

/**
 * 修改用户角色
 * @param {object} params UserRoleDto
 * @param {number} params.userId
 * @param {string} params.roleId
 * @returns
 */
export function putUserRole(params: PutUserRoleParams): Promise<PutUserRoleRes> {
    const config:HttpOptions  = {
        msg: false,
        token: true,
        load: false,
    }
    return http.put(`/userRole`, params,config);
}